package com.keliangliu.demo.lock;

import java.util.concurrent.locks.LockSupport;

/**
 * 排队执行
 */
public class LineUpSoutDemo {


    static Thread t1 = null;
    static Thread t2 = null;

    static Thread t3 = null;


    public static void main(String[] args) {

        String[] charA = {"1","2","3","4"};
        String[] charB = {"A","B","C","D"};
        String[] charC = {"a","b","c","d"};


       t1 =  new Thread(()-> {
            for(String c :charA) {
                //t1,先打印
                System.out.println(c);
                //然后唤醒t2;
                LockSupport.unpark(t2);
                //然后等待
                LockSupport.park();

            }

        },"t1");


       t2 =  new Thread(()-> {
            for(String c :charB) {
                //首先等待
                LockSupport.park();
                //然后打印
                System.out.println(c);
                //唤醒t1
                LockSupport.unpark(t3);

            }


        },"t2");

       t3 = new Thread(() -> {
           for(String c : charC) {
               LockSupport.park();
               System.out.println(c);
               LockSupport.unpark(t1);
           }

       },"t3");

        t1.start();
        t2.start();
        t3.start();


    }


}
